/*----------------------------------------\ | Check the existence of a macro function; | |-------------------------------------------| |--------------------------------------------------------------------| |---------------------------| | Inputs: | | MacroNam - Name of macro to look for. | | rcexist - Name of macro variable to contain return code | | Note: caller must ensure macro variable &rcexist is global scoped| | before calling MacroFunChk. | | Result: | | 0, The macro has not been compiled. | | 1, The macro has been compiled. | |--------------------------------------| |--------------------------------------------------------------------| |---------------------------------------| | Example: | | %global rc; | | %MacroFunChk(prt, rc); | | %MacroFuncChk(%nrstr(%prt)); | | Usage: %MacroFunChk (MacroNam, rcexist); | \----------------------------------------*/ %macro MacroFunChk (MacroNam, rcexist); /*--------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 9-28-2001 9:30pm; | | Purpose: Check the existence of a Macro | | Fucntion; | \--------------------------------------------*/ %local MacFound yesno; %if (%index(&MacroNam,%quote(%))) %then %let MacroNam=%sysfunc(compress(&MacroNam, %quote(%))); %let MacroNam=%sysfunc(dequote(&MacroNam)); %let MacFound = 0; /* initialize to not found */ /* Create a data set, MacroLst, containing macro names */ proc catalog catalog=work.sasmacr; contents out=MacroLst; quit; /* Look for macro name in MacroLst data set */ data _null_; set MacroLst (keep=name); if upcase(name) = "%upcase(%quote(&MacroNam))" then do; call symput ('MacFound',"1"); /* Output value set to found */ stop; end; run; %if &MacFound=1 %then %do; %if (%quote(&rcexist) ne) %then %let &rcexist = &MacFound; %let yesno=YES; %end; %else %do; %let MacFound=0; %if (%quote(&rcexist) ne) %then %let &rcexist = &MacFound; %let yesno=NO; %end; %put --> Note: %nrstr(%%)&MacroNam Exist: &yesno.. ; %mend MacroFunChk;